import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    // return Scaffold(
    //   body: Padding(
    //     padding: EdgeInsets.all(MediaQuery.of(context).padding.top),
    //     child: Column(
    //       children: [
    //         TopBar(),
    //       ],
    //     ),
    //   ),
    // );
    return Scaffold(
      body: Padding(
        padding: EdgeInsets.all(MediaQuery.of(context).padding.top),
        child: Container(
          width: MediaQuery.of(context).size.width -
              MediaQuery.of(context).padding.left -
              MediaQuery.of(context).padding.right,
          height: MediaQuery.of(context).size.height -
              MediaQuery.of(context).padding.bottom -
              MediaQuery.of(context).padding.top,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              TopBar(),
              Expanded(
                child: Category(),
              ),
              HotMessage(),
            ],
          ),
        ),
      ),
    );
  }
}

class TopBar extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        children: [
          Image.asset(
            "assets/images/logo.png",
            width: 55,
            height: 55,
          ),
          Text(
            "巴蜀拾艺人",
            style: TextStyle(
              fontFamily: "pang",
            ),
          ),
        ],
        textBaseline: TextBaseline.alphabetic,
      ),
    );
  }
}

Widget categoryItem(String title, Color colors) {
  return ClipRRect(
    borderRadius: BorderRadius.circular(25),
    child: Container(
      // color: colors,
      alignment: Alignment.center,
      decoration: BoxDecoration(
        boxShadow: [
          BoxShadow(
            color: Colors.white,
            blurRadius: 10.0,
          ),
          BoxShadow(color: Colors.white, blurRadius: 34.0, spreadRadius: 7.0),
          BoxShadow(
            color: colors,
            blurRadius: 10.0,
          ),
        ],
      ),
      child: Text(
        title,
        style: TextStyle(
          color: Colors.white,
          fontSize: 33,
          fontFamily: "pang",
        ),
      ),
    ),
  );
}

class Category extends StatefulWidget {
  @override
  _CategoryState createState() => _CategoryState();
}

class _CategoryState extends State<Category> {
  @override
  Widget build(BuildContext context) {
    return GridView(
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 3,
        childAspectRatio: 1.0,
        crossAxisSpacing: 60,
        mainAxisSpacing: 60,
      ),
      children: <Widget>[
        categoryItem("期刊", Colors.blueAccent),
        categoryItem("图书", Colors.amber),
        categoryItem("文集", Colors.lightGreen),
        categoryItem("图片", Colors.lightGreen),
        categoryItem("影音", Colors.pink),
        categoryItem("数据", Colors.purple),
      ],
    );
  }
}

class HotMessage extends StatefulWidget {
  @override
  _HotMessageState createState() => _HotMessageState();
}

class _HotMessageState extends State<HotMessage> {
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}
